package us.gaaoc.framework.dao;
/*
 * @author Frank
 */
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.hibernate.Query;

import us.gaaoc.framework.model.CaseRecordAction;
import us.gaaoc.framework.model.Court;
import us.gaaoc.framework.model.DocPageRange;
import us.gaaoc.framework.model.DocumentInstance;
import us.gaaoc.framework.model.DocumentPackage;

public class DocumentPackageDAOHibernate extends
GenericHibernateDAO<DocumentPackage, String, DocumentPackageDAO> implements
DocumentPackageDAO {
	
	public DocumentPackage findPackageNameByUuid(String uuid) {
		Query q = getSession().createQuery("from DocumentPackage dp where dp.uuid = ?");
		q.setString(0, uuid);
		return  (DocumentPackage)q.uniqueResult();
	}
	
	public DocumentPackage findDocumentPackageByName(String name) {
		Query q = getSession().createQuery("from DocumentPackage dp where dp.packageName = ?");
		q.setString(0, name);
		return (DocumentPackage)q.uniqueResult();
	}

	/* (non-Javadoc)
	 * @see us.gaaoc.framework.dao.DocumentPackageDAO#findDocumentPackageByName(us.gaaoc.framework.model.Court)
	 */
	public List<DocumentPackage> findDocumentPackageByName(Court court) {
		LOG.debug("Inside getting DocumentPackagesByAlias");
		ArrayList<DocumentPackage> docPackageList = new ArrayList<DocumentPackage>();
		
		Query q = this.getSession().createQuery("from DocumentPackage dp where dp.court=? order by packageName");
		q.setEntity(0,court);
		List l = q.list();
		Iterator i = l.iterator();
		while (i.hasNext()){
			docPackageList.add((DocumentPackage)i.next());			
		}
		return docPackageList;
	}
	
	
	public List<DocumentPackage> findDocumentPackageByCourtandCaseRecordAction(Court court,CaseRecordAction cra)
	{
		LOG.debug("Inside getting findDocumentPackageByCourtandCaseRecordAction");
		ArrayList<DocumentPackage> docPackageList = new ArrayList<DocumentPackage>();
		Query q = this.getSession().createQuery("from DocumentPackage dp where dp.court=? and dp.caseRecordAction=? order by packageName");
		q.setEntity(0,court);
		q.setEntity(1, cra);
		List l = q.list();
		Iterator i = l.iterator();
		while (i.hasNext()){
			docPackageList.add((DocumentPackage)i.next());			
		}
		
		
		return docPackageList;

	}

	
}